using System;
using System.Collections.Generic;
using System.Text;
using Pine.Lexer;

namespace Pine.SourceParser.Tree
{
	public class ForStatement : Statement
	{
		public Statement Begin, End, Content;
		public Expression Condition;
		public string Name;
		
		public ForStatement() : this(null, null, null, null) {}
		
		public ForStatement(Statement begin, Expression condition, Statement end, Statement content)
			: this(null, begin, condition, end, content) {}
		
		public ForStatement(string name, Statement begin, Expression condition, Statement end, Statement content)
		{
			Begin = begin;
			End = end;
			Condition = condition;
			Content = content;
			Name = name;
		}
		
		public override string ToString()
		{
			StringBuilder str = new StringBuilder();
			if (Name != null) {
				str.Append(Name);
				str.Append(": ");
			}
			
			str.Append("for (");
			
			if (Begin != null)
				str.Append(Begin.ToString());
			else
				str.Append(";");
			
			if (Condition != null)
				str.Append(Condition.ToString());
			
			str.Append(";");
			
			if (End != null)
				str.Append(End.ToString().TrimEnd(' ', '\n', ';'));
			
			str.Append(") ");
			
			str.Append(Content.ToString());
			
			return str.ToString();
		}
	}
}

